<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <ul>
        <li>111</li>
        <li>222</li>
        <li>333</li>
    </ul>
    <script>
        var uli = document.querySelectorAll('li');
        console.log(uli);
        for (let index in uli) {
            uli[index].onmouseover = showBgColor(index, 'pink');
            uli[index].onmouseout = showBgColor(index, '');
            function showBgColor(index, color) {
                return function () {
                    uli[index].style.background = color;
                }
            }
        }




        // var prize = ['iphone12', 'iphone11', 'iphonex', 'iphone8', 'iphone7'];

        // 统计字符串中字母出现的次数
        var str = 'ababcdeeeffhhljlkom';
        // var obj = {}; //定义一个空对象
        var obj = []; //定义一个空数组也可以
        for (let i = 0; i < str.length; i++) {
            if (obj[str[i]] == undefined) {
                obj[str[i]] = 1;
            } else {
                obj[str[i]]++;
            }
        }
        console.log(obj);

        //关联数组写法
        var arr = [];
        arr['name'] = 'luojianming';
        arr['age'] = 18;
        arr['love'] = 'programming';
        console.log(arr);
    </script>
</body>

</html>